package com.kyjszj.modules.task.controller;

import com.kyjszj.core.query.wrapper.EntityWrapper;
import com.kyjszj.modules.product.entity.Product;
import com.kyjszj.modules.product.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Component
public class ProductTask {


    private IProductService productService;

    @Autowired
    public void setProductService(IProductService productService) {
        this.productService = productService;
    }


    public void checkExpridProduct() throws ParseException {
        List<Product> lists=productService.selectList(new EntityWrapper<Product>());
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (Product product:lists) {
            Date date1=sf.parse(product.getCouponEndTime());
            if(date1.compareTo(new Date())>0||product.getCouponTotalCount()==0){
                productService.deleteById(product.getId());
            }
        }
    }
}
